<template>
  <el-button size="small" type="primary" @click="exportData" :loading="loading">{{buttonText}}</el-button>
</template>

<script>
import {deepCopy} from "@/utils";

export default {
  name: "ExportButton",
  props:{
    queryParams:{
      type: Object,
    },
    func:{
      type: Function,
      required: true,
    }
  },
  data(){
    return {
      loading: false,
      buttonText: '导 出'
    }
  },
  methods:{
    exportData(){
      const exportParams = deepCopy(this.queryParams)
      exportParams.page = 1;
      exportParams.pageSize = 300000;
      exportParams.export = 1;
      this.loading = true
      this.buttonText = '导出中...'
      this.func(exportParams)
        .then(res=>{
          this.loading = false
          this.buttonText = '导 出'
          if(res.error === 0){
            window.open(res.data.excelPath,"_blank");
          }
        })
    }
  },
}
</script>

<style scoped>

</style>
